package com.trippin.DB.entities;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.beoui.geocell.GeocellManager;
import com.beoui.geocell.annotations.Geocells;
import com.beoui.geocell.annotations.Latitude;
import com.beoui.geocell.annotations.Longitude;
import com.beoui.geocell.model.BoundingBox;
import com.beoui.geocell.model.Point;
import com.google.appengine.api.datastore.Key;
import com.google.gson.annotations.Expose;
import com.trippin.Utils.TimeUtil;

@PersistenceCapable
public class StickyNoteEntity implements TrippinEntity, Serializable {

	private static final long serialVersionUID = 1L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	@Expose
	private long id;
	
	@Persistent
	@Expose
	private long userId;
	
	@Persistent
	@Expose
	private String title;
	
	@Persistent
	@Expose
	private String description;
	
	@Persistent
	@Longitude
	@Expose
	private double longitude;

	@Persistent
	@Latitude
	@Expose
	private double latitude;
	
	@Persistent
	BoundingBox boundingBox;

	@Persistent
	@Geocells
	private List<String> geoCellsData;
	
	@Persistent
	@Expose
	private Date start;
	
	@Persistent
	@Expose
	private Date end;

	@Persistent
	@Expose
	private Date createdOn;
	
	
	public StickyNoteEntity(long userId, double longitude, double latitude, String title, Date start, Date end, String description) throws IOException {
		TimeUtil.timeValidator(0,start,end,true);
		this.userId = userId;
		this.longitude = longitude;
		this.latitude = latitude;
		this.title = title;
		this.start = start;
		this.end = end;
		this.description = description;
		this.createdOn = new Date();
		
		setGeoCellsData();
	}

	
	public Key getKey() {
		return key;
	}

	public long getId() {
		return id;
	}


	public void setId() {
		this.id = key.getId();
	}


	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = key.getId();
	}

	public double getLongitude() {
		return longitude;
	}


	public double getLatitude() {
		return latitude;
	}
		
	public BoundingBox getBoundingBox() {
		return boundingBox;
	}

	public List<String> getGeoCellsData() {
		return geoCellsData;
	}

	public void setGeoCellsData() {
		Point p = new Point();
		p.setLat(this.latitude);
		p.setLon(this.longitude);
		this.geoCellsData = GeocellManager.generateGeoCell(p);
	}

	public String getTitle() {
		return title;
	}


	public Date getStart() {
		return start;
	}


	public Date getEnd() {
		return end;
	}


	public String getDescription() {
		return description;
	}


	public void setDescription(String notes) {
		this.description = notes;
	}


	public Date getCreatedOn() {
		return createdOn;
	}


}
